import request from "@/utils/request";
import type {
  AllSPUAttributeList,
  Spu,
  SPUAttributeListAPI,
  SPUBrandList,
  SPUImageList,
  SpuListObjectType,
} from "./type/spu";
//获取SUP一般数据接口(指的是SPU页面首页的)
export const getSPUData = (page: number, limit: number, category3Id: number) =>
  request.get<any, SpuListObjectType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );

//获取SPU所有品牌数据
export const getSPUBrandList = () =>
  request.get<any, SPUBrandList>(
    "/admin/product/baseTrademark/getTrademarkList"
  );
//获取指定的照片墙数据
export const getSPUPhotosList = (spuId: number | string) =>
  request.get<any, SPUImageList>(`/admin/product/spuImageList/${spuId}`);
//获取已有的SPU销售属性和属性值
export const getSPUAttributeAndValue = (spuId: number | string) =>
  request.get<any, SPUAttributeListAPI>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
//获取全部SPU商品属性与上面一个接口是取差值，上面没有的放入select框
export const getAllSPUAttributeAndValue = () =>
  request.get<any, AllSPUAttributeList>("/admin/product/baseSaleAttrList");

//SPU数据的添加与修改
export const addAndUpdadteSPUProduct = (data: Spu) => {
  //有ID是更新
  if (data.id) {
    return request.post("/admin/product/updateSpuInfo", data);
  } //没有是添加
  else {
    return request.post("/admin/product/saveSpuInfo", data);
  }
};
//添加SKU接口
export const addSKUAPI = (data: any) => {
  return request.post<any, any>("/admin/product/saveSkuInfo", data);
};
//查看SKU详情接口
export const lookSKUListAPI = (spuId: number) => {
  return request.get(`/admin/product/findBySpuId/${spuId}`);
};
//删除SPU接口
export const delSPUAPI = (spuId: number) => {
  return request.delete(`/admin/product/deleteSpu/${spuId}`);
};
